<?php
namespace Admin\Controller;
use Think\Controller;
class loginController extends Controller
{
    public function login()
    {
       /*M('Admin')->add([
            'admin_name'=>'admin',
            'email'=>'kuchlen2',
            'password'=>md5('admin')
        ]);*/
        $this->display();
    }

    public function handler()
    {
        $admin_name=I('post.username');
        $password=I('post.password');
        $admin = M('Admin')->where(['admin_name'=>$admin_name])->find();
        //var_dump($admin);die;
        if(!$admin) $this->error('用户名不存在');

        if(md5($password) != $admin['password']) $this->error('密码错误');
        //echo "is here";
        $user = [
            'name'=>$admin['admin_name'],
            'id'=>$admin['id']
        ];
        session('blog_admin',$user);
        $this->success('login ok',U('Index/index'));
    }
}